﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ArxOne.MrAdvice.Advice;
using Caliburn.Micro;

namespace JY.Wpf.Core.Tools
{
    /// <summary>
    /// 属性通知特性
    /// </summary>
    [AttributeUsage(AttributeTargets.All , AllowMultiple = false, Inherited = true)]
    public class NotifyPropertyChangedAttribute : Attribute, IPropertyAdvice
    {
        public void Advise(PropertyAdviceContext context)
        {
            if (context.IsGetter)
            {
                context.Proceed();
            }
            else
            {
                context.Proceed();
                if (context.IsGetter) return;
                if (context.Target is INotifyPropertyChangedEx propertyChanged)
                {
                    propertyChanged.NotifyOfPropertyChange(context.TargetName);
                }
            }
        }

    }
}
